### Loading in the Data and Libraries ###
setwd("")
data<-read.csv("02_Clean Racial Shift Replication.csv")

library(sandwich)
library(lmtest)
library(stargazer)

#### Regressions Where Ideology Interacts with the Treatment Effect to Assess Heterogeneous Effects ####

### Status Change ###
SC1_C<-lm(SC_scale~ Treatment*cons_ideo_scale, data= data)
SC1_C<-coeftest(SC1_C, vcov= vcovHC, type= "HC1") 
pnorm(SC1_C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Psychological Mechanisms ###
# symbolic threat
Scale_reg1C<-lm(ST_scale~ Treatment*cons_ideo_scale, data= data)
Scale_reg1C<-coeftest(Scale_reg1C, vcov= vcovHC, type= "HC1") 
pnorm(Scale_reg1C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# realistic threat
Scale_reg2C<-lm(RT_scale~ Treatment*cons_ideo_scale, data= data)
Scale_reg2C<-coeftest(Scale_reg2C, vcov= vcovHC, type= "HC1") 
pnorm(Scale_reg2C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# prototypicality threat
Scale_reg3C<-lm(PT_scale_full~ Treatment*cons_ideo_scale, data= data)
Scale_reg3C<-coeftest(Scale_reg3C, vcov= vcovHC, type= "HC1") 
pnorm(Scale_reg3C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Group Attitudes ###
# views of black americans
FT_reg1C<-lm(Black_FT~ Treatment*cons_ideo_scale, data= data)
FT_reg1C<-coeftest(FT_reg1C, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg1C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of latino americans
FT_reg2C<-lm(Latinos_FT~ Treatment*cons_ideo_scale, data= data)
FT_reg2C<-coeftest(FT_reg2C, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg2C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of asian americans
FT_reg3C<-lm(Asian_FT~ Treatment*cons_ideo_scale, data= data)
FT_reg3C<-coeftest(FT_reg3C, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg3C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of white americans
FT_reg4C<-lm(White_FT~ Treatment*cons_ideo_scale, data= data)
FT_reg4C<-coeftest(FT_reg4C, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg4C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of blm
FT_reg5C<-lm(BLM_FT~ Treatment*cons_ideo_scale, data= data)
FT_reg5C<-coeftest(FT_reg5C, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg5C[6:8, 3], lower.tail = T) # print for reported significance tests, full results reported in Appendix C

# views of the alt right
FT_reg6C<-lm(Alt_Right_FT~ Treatment*cons_ideo_scale, data= data)
FT_reg6C<-coeftest(FT_reg6C, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg6C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Policy Support ###
# racial policy
Pol_reg1C<-lm(racialpolicy_scale~ Treatment*cons_ideo_scale, data= data)
Pol_reg1C<-coeftest(Pol_reg1C, vcov= vcovHC, type= "HC1") 
pnorm(Pol_reg1C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# nonracial policy
Pol_reg2C<-lm(nonracialpolicy_scale~ Treatment*cons_ideo_scale, data= data)
Pol_reg2C<-coeftest(Pol_reg2C, vcov= vcovHC, type= "HC1") 
pnorm(Pol_reg2C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Participation ###
# personal backlash participation
Part_reg1C<-lm(backlash_person~ Treatment*cons_ideo_scale, data= data)
Part_reg1C<-coeftest(Part_reg1C, vcov= vcovHC, type= "HC1") 
pnorm(Part_reg1C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# political backlash participation
Part_reg2C<-lm(backlash_pol~ Treatment*cons_ideo_scale, data= data)
Part_reg2C<-coeftest(Part_reg2C, vcov= vcovHC, type= "HC1") 
pnorm(Part_reg2C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# political supportive participation
Part_reg3C<-lm(support_pol~ Treatment*cons_ideo_scale, data= data)
Part_reg3C<-coeftest(Part_reg3C, vcov= vcovHC, type= "HC1") 
pnorm(Part_reg3C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# personal supportive participation
Part_reg4C<-lm(support_person~ Treatment*cons_ideo_scale, data= data)
Part_reg4C<-coeftest(Part_reg4C, vcov= vcovHC, type= "HC1")
pnorm(Part_reg4C[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

#### Regressions Where Partisanship Interacts with the Treatment Effect to Assess Heterogeneous Effects ####

### Status Change ###
SC1_P<-lm(SC_scale~ Treatment*political_party_preference, data= data)
SC1_P<-coeftest(SC1_P, vcov= vcovHC, type= "HC1") 
pnorm(SC1_P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Psychological Mechanisms ###
# symbolic threat
Scale_reg1P<-lm(ST_scale~ Treatment*political_party_preference, data= data)
Scale_reg1P<-coeftest(Scale_reg1P, vcov= vcovHC, type= "HC1") 
pnorm(Scale_reg1P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# realistic threat
Scale_reg2P<-lm(RT_scale~ Treatment*political_party_preference, data= data)
Scale_reg2P<-coeftest(Scale_reg2P, vcov= vcovHC, type= "HC1") 
pnorm(Scale_reg2P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# prototypicality threat
Scale_reg3P<-lm(PT_scale_full~ Treatment*political_party_preference, data= data)
Scale_reg3P<-coeftest(Scale_reg3P, vcov= vcovHC, type= "HC1") 
pnorm(Scale_reg3P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Group Attitudes ###
# views of black americans
FT_reg1P<-lm(Black_FT~ Treatment*political_party_preference, data= data)
FT_reg1P<-coeftest(FT_reg1P, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg1P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of latino americans
FT_reg2P<-lm(Latinos_FT~ Treatment*political_party_preference, data= data)
FT_reg2P<-coeftest(FT_reg2P, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg2P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of asian americans
FT_reg3P<-lm(Asian_FT~ Treatment*political_party_preference, data= data)
FT_reg3P<-coeftest(FT_reg3P, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg3P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of white americans
FT_reg4P<-lm(White_FT~ Treatment*political_party_preference, data= data)
FT_reg4P<-coeftest(FT_reg4P, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg4P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# views of blm
FT_reg5P<-lm(BLM_FT~ Treatment*political_party_preference, data= data)
FT_reg5P<-coeftest(FT_reg5P, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg5P[6:8, 3], lower.tail = T) # print for reported significance tests, full results reported in Appendix C

# views of the alt right
FT_reg6P<-lm(Alt_Right_FT~ Treatment*political_party_preference, data= data)
FT_reg6P<-coeftest(FT_reg6P, vcov= vcovHC, type= "HC1") 
pnorm(FT_reg6P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Policy Support ###
# racial policy
Pol_reg1P<-lm(racialpolicy_scale~ Treatment*political_party_preference, data= data)
Pol_reg1P<-coeftest(Pol_reg1P, vcov= vcovHC, type= "HC1") 
pnorm(Pol_reg1P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# nonracial policy
Pol_reg2P<-lm(nonracialpolicy_scale~ Treatment*political_party_preference, data= data)
Pol_reg2P<-coeftest(Pol_reg2P, vcov= vcovHC, type= "HC1") 
pnorm(Pol_reg2P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

### Participation ###
# personal backlash participation
Part_reg1P<-lm(backlash_person~ Treatment*political_party_preference, data= data)
Part_reg1P<-coeftest(Part_reg1P, vcov= vcovHC, type= "HC1") 
pnorm(Part_reg1P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# political bachlash participation
Part_reg2P<-lm(backlash_pol~ Treatment*political_party_preference, data= data)
Part_reg2P<-coeftest(Part_reg2P, vcov= vcovHC, type= "HC1") 
pnorm(Part_reg2P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# political supportive participation
Part_reg3P<-lm(support_pol~ Treatment*political_party_preference, data= data)
Part_reg3P<-coeftest(Part_reg3P, vcov= vcovHC, type= "HC1") 
pnorm(Part_reg3P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

# personal supportive participation
Part_reg4P<-lm(support_person~ Treatment*political_party_preference, data= data)
Part_reg4P<-coeftest(Part_reg4P, vcov= vcovHC, type= "HC1")
pnorm(Part_reg4P[6:8, 3], lower.tail = F) # print for reported significance tests, full results reported in Appendix C

#### Exporting Regressions  Where Ideology Interacts with the Treatment Effect to Assess Heterogeneous Effects ####

### Table C8 ###
stargazer(SC1_C,
          align= T,
          dep.var.labels = c("Status Change"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Conservatism", "Cultural Shift x Conservatism",
                                "Political Shift x Conservatism", "Population Shift x Conservatism"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C9 ###
stargazer(Scale_reg1C, Scale_reg2C, Scale_reg3C,
          align= T,
          column.labels = c("Symbolic Threat", "Realistic Threat", "Prototypicality Threat"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Conservatism", "Cultural Shift x Conservatism",
                                "Political Shift x Conservatism", "Population Shift x Conservatism"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C10 ###
stargazer(FT_reg1C, FT_reg2C, FT_reg3C, FT_reg5C,
          align= T,
          column.labels = c("Black FT", "Latino FT", "Asian FT", "BLM FT"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Conservatism", "Cultural Shift x Conservatism",
                                "Political Shift x Conservatism", "Population Shift x Conservatism"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C11 ###
stargazer(FT_reg4C, FT_reg6C,
          align= T,
          column.labels = c("White FT", "Alt Right FT"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Conservatism", "Cultural Shift x Conservatism",
                                "Political Shift x Conservatism", "Population Shift x Conservatism"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C12 ###
stargazer(Pol_reg1C, Pol_reg2C,
          align= T,
          column.labels = c("Racial Policy Scale", "Nonracial Policy Scale"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Conservatism", "Cultural Shift x Conservatism",
                                "Political Shift x Conservatism", "Population Shift x Conservatism"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C13 ###
stargazer(Part_reg2C, Part_reg1C, Part_reg3C, Part_reg4C,
          align= T,
          column.labels = c("Political Backlash", "Personal Backlash",
                            "Political Supportive", "Personal Supportive"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Conservatism", "Cultural Shift x Conservatism",
                                "Political Shift x Conservatism", "Population Shift x Conservatism"),
          star.cutoffs = c(0.05, 0.01, 0.001))


#### Printing Regressions Interacted with Partisanship ####

### Table C14 ###
stargazer(SC1_P,
          align= T,
          dep.var.labels = c("Status Change"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Partisanship", "Cultural Shift x Partisanship",
                                "Political Shift x Partisanship", "Population Shift x Partisanship"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C15 ###
stargazer(Scale_reg1P, Scale_reg2P, Scale_reg3P,
          align= T,
          column.labels = c("Symbolic Threat", "Realistic Threat", "Prototypicality Threat"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Partisanship", "Cultural Shift x Partisanship",
                                "Political Shift x Partisanship", "Population Shift x Partisanship"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C16 ###
stargazer(FT_reg1P, FT_reg2P, FT_reg3P, FT_reg5P,
          align= T,
          column.labels = c("Black FT", "Latino FT", "Asian FT", "BLM FT"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Partisanship", "Cultural Shift x Partisanship",
                                "Political Shift x Partisanship", "Population Shift x Partisanship"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C17 ###
stargazer(FT_reg4P, FT_reg6P,
          align= T,
          column.labels = c("White FT", "Alt Right FT"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Partisanship", "Cultural Shift x Partisanship",
                                "Political Shift x Partisanship", "Population Shift x Partisanship"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C18 ###
stargazer(Pol_reg1P, Pol_reg2P,
          align= T,
          column.labels = c("Racial Policy Scale", "Nonracial Policy Scale"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Partisanship", "Cultural Shift x Partisanship",
                                "Political Shift x Partisanship", "Population Shift x Partisanship"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table C19 ###
stargazer(Part_reg2P, Part_reg1P, Part_reg3P, Part_reg4P,
          align= T,
          column.labels = c("Political Backlash", "Personal Backlash",
                            "Political Supportive", "Personal Supportive"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment", "Partisanship", "Cultural Shift x Partisanship",
                                "Political Shift x Partisanship", "Population Shift x Partisanship"),
          star.cutoffs = c(0.05, 0.01, 0.001))
